package pw.hais.braintwists.dao;

import java.util.HashMap;
import java.util.Map;

import pw.hais.braintwists.model.User;
import pw.hais.http.Http;
import pw.hais.http.base.OnHttpListener;

/**
 * Created by Hais1992 on 2015/12/11.
 */
public class LeanCloudDao {
    public static final String SERVER = "https://leancloud.cn:443/1.1";
    private static final String URL_REG_USER = SERVER + "/users";
    private static final String URL_LOGIN_USER = SERVER + "/login";


    public static Map<String, String> header = new HashMap<>();

    static {
        header.put("X-LC-Id", "yQINrzTomgOiQmPJspiEK7p1-gzGzoHsz");
        header.put("X-LC-Key", "RLi3bXKOVj5ROtyvfc4WwH9p");
    }


    public static void regUser(String username, String password, String name, OnHttpListener<User> listener) {
        Map<String, String> data = new HashMap<>();
        data.put("username", username);
        data.put("password", password);
        data.put("name", name);
        Http.postBody(URL_REG_USER, header, data, listener);
    }

    public static void loginUser(String username, String password, OnHttpListener<User> listener) {
        Map<String, String> data = new HashMap<>();
        data.put("username", username);
        data.put("password", password);
        Http.postBody(URL_LOGIN_USER, header, data, listener);
    }
}
